package com.shuang.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.shuang.mapper.DbGoodsFormatMapper;
import com.shuang.pojo.DbGoodsFormat;
import com.shuang.pojo.DbGoodsFormatExample;
import com.shuang.pojo.DbGoodsFormatExample.Criteria;
import com.shuang.pojo.ExtendDbGoodsFormat;
import com.shuang.service.DbGoodsFormatService;
@Service("dbGoodsFormatService")
public class DbGoodsFormatServiceImpl implements DbGoodsFormatService {

	@Resource(name="dbGoodsFormatMapper")
	private DbGoodsFormatMapper dbGoodsFormatMapper;
	@Override
	public List<ExtendDbGoodsFormat> findFormatById(Long cId) {
		DbGoodsFormatExample example = new DbGoodsFormatExample();
		Criteria criteria = example.createCriteria();
		criteria.andCIdEqualTo(cId);
		List<ExtendDbGoodsFormat> list=dbGoodsFormatMapper.selectExtendByExample(example);
		return list;
	}
	@Override
	public Map<String, Object> saveFormatParam(Long cId, String paramData) throws Exception {
		DbGoodsFormat record = new DbGoodsFormat();
		record.setcId(cId);
		record.setGfCreateTime(new Date());
		record.setGfParamData(paramData);
		int result = dbGoodsFormatMapper.insert(record);
		Map<String,Object> map=new HashMap<String, Object>();
		if(result>0){
			map.put("status", 200);
		}else{
			map.put("status", 500);
			throw new Exception();
		}
		
		return map;
	}
	@Override
	public Map<String, Object> updateFormatParam(Long gfId, String paramData) throws Exception {
		DbGoodsFormat record = new DbGoodsFormat();
		record.setGfId(gfId);
		record.setGfUpdateTime(new Date());
		record.setGfParamData(paramData);
		int result=dbGoodsFormatMapper.updateByPrimaryKeySelective(record);
		Map<String,Object> map=new HashMap<String, Object>();
		if(result>0){
			map.put("status", 200);
		}else{
			map.put("status", 500);
			throw new Exception();
		}
		return map;
	}
	@Override
	public Map<String, Object> selectFormatInfoByCid(Long cId) {
		DbGoodsFormatExample example = new DbGoodsFormatExample();
		Criteria criteria = example.createCriteria();
		criteria.andCIdEqualTo(cId);
		List<DbGoodsFormat> result = dbGoodsFormatMapper.selectByExample(example);
		Map<String,Object> map=new HashMap<String, Object>();
		if(result!=null&&result.size()>0){
			map.put("status", 200);
			map.put("data", result.get(0));
		}else{
			map.put("status",400);
		}
		return map;
	}

}
